<template>
  <a-modal
    title="主合同"
    @ok="ok"
    @cancel="cancel"
    :visible="visible"
    class="large-modal"
  >
    <searchData :search-data="searchArr" @search="search" />

    <a-card>
      <b-table
        ref="table"
        :scroll="{ x: 1800 }"
        :columns="columns"
        :request="loadData"
        :selectConfig="{use:true,type:'radio',rowKey:'id'}"
        @row-click="rowClick"
      >
        <span slot="index" slot-scope="text, record, index">{{ index + 1 }}</span>
      </b-table>
    </a-card>
  </a-modal>
</template>
<script>
import subcontract from '@/api/legal/branchContract/subcontract'
import SelectSubCompany from '@/components/Select/SelectSubCompany'
import SelectProject from '@/components/Select/SelectProject'
import OrgTreeSelect from '@/components/OrgTreeSelect'
import BSelect from '@/components/BComponents/BSelect'

export default {
  name: 'mainContractDialog',
  components: {},
  props: {
    visible: false
  },
  data() {
    return {
      columns: [
        {
          title: '序号',
          width: 70,
          scopedSlots: { customRender: 'index' }
        },
        {
          title: '所属分公司',
          dataIndex: 'branchComName'
        },
        {
          title: '项目名称',
          dataIndex: 'projectName'
        },
        {
          title: '合同名称',
          dataIndex: 'contractName'
        },
        {
          title: '合同编号',
          dataIndex: 'code'
        },
        {
          title: '分包商',
          dataIndex: 'subSupplyCompany'
        },
        {
          title: '合同种类',
          dataIndex: 'localContractTypeStr'
        },
        {
          title: '分包方式',
          dataIndex: 'contractTypeStr'
        },
        {
          title: '合同额（含税)(元）',
          dataIndex: 'contractInTaxAmount'
        },
        {
          title: '合同来源',
          dataIndex: 'fromStatusStr'
        },
        {
          title: '状态',
          dataIndex: 'auditStatusStr',
          scopedSlots: { customRender: 'auditStatusStr' }
        }
      ],
      searchArr: [
        // 搜索框
        {
          name: '所属单位',
          valueKey: 'searchQuery',
          type: OrgTreeSelect,
        },
        // {
        //   name: '所属分公司',
        //   type: SelectSubCompany,
        //   valueKey: 'branchComId',
        //   autoSelected: this.SelectSubCompanyAutoSelected
        // },
        // {
        //   name: '项目名称',
        //   type: SelectProject,
        //   autoSelected: this.SelectProjectAutoSelected,
        //   valueKey: 'projectId',
        //   keyValue: 'branchComId'
        // },
        {
          name: '分包商',
          type: 'input',
          value: 'subSupplyCompany'
        },
        {
          name: '合同名称',
          type: 'input',
          value: 'contractName'
        },
        {
          name: '合同编号',
          type: 'input',
          value: 'code'
        },
        {
          name: '分包方式',
          type: 'select',
          value: 'contractTypeId',
          data: this.contractTypeData,
          request: async () => {
            let res = await subcontract.typesLabel({ query: { type: 21 } })
            if (res.code === this.SUCCESS_CODE) {
              // eslint-disable-next-line vue/no-side-effects-in-computed-properties
              this.contractTypeData = res.data.map((v) => {
                return { label: v.name, value: v.id }
              })
            }
            return res
          }
        },
        {
          name: '合同来源',
          type: BSelect,
          projectId: 'fromStatus',
          data: [],
          list: [
            { id: 0, name: '云筑' },
            { id: 1, name: '本平台新增' }
          ]
        }
      ],
      queryParams: {},
      loadData: (parameter) => {
        const q = Object.assign({}, parameter, { query: this.queryParams })
        console.log(q.query)
        q.query.localContractType = 0
        q.query.auditStatus = 'PAST'
        return subcontract.list(q)
      },
      selectRows: null
    }
  },
  computed: {},
  watch: {},
  created() {
  },
  methods: {
    rowClick(e, row) {
      this.selectRows = row
    },
    cancel() {
      this.$emit('update:visible', false)
    },
    ok() {
      if (this.selectRows === null) {
        return this.$noticeWarning('请选择数据')
      }
      this.$emit('ok', this.selectRows)
      this.cancel()
    },
    search(val) {
      this.queryParams = val || {}
      this.$refs.table && this.$refs.table.refresh()
    }
  }
}
</script>